package com.syedu.day16;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * description：桥接器 -- 把字节流转换成字符流的转换器
 * java.io.InputStreamReader        把字节输入流转换成字符输入流
 * java.io.OutputStreamWriter       把字节输出流转换成字符输出流
 *
 * @author Administrator
 * @date 2022/4/8 9:17
 */
public class InputStreamReaderDemo {
    public static void main(String[] args) {
        //把字节流转换成字符流
        //注意:第二个参数表示转换后使用的字符集,默认为当前项目文件编码(可以省略)
        //try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("D:\\BAM练习.txt")){
        //try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("D:\\BAM练习.txt"), Charset.defaultCharset())) {
        /*try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("D:\\BAM练习.txt"), "UTF-8")) {
            int len = -1;
            while ((len = inputStreamReader.read()) != -1) {
                System.out.print((char) len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }*/

        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        /**
         * 面试题:
         * 请实现获取用户键盘输入的功能(不允许使用Scanner)
         */
        try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in))) {
            System.out.println("请您输入内容: ");
            //如果标准输入流System.in没有数据,则转换的流就没有数据,通过readLine()方法读取数据时就会产生阻塞,等待数据的产生!
            String line = bufferedReader.readLine();
            System.out.println("您输入的内容为: " + line);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}